package com.sdcqjy.property.presenter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sdcqjy.mylibrary.http.BaseRequestBack;
import com.sdcqjy.mylibrary.http.BaseRet;
import com.sdcqjy.mylibrary.http.HttpClient;
import com.sdcqjy.property.AppLL;
import com.sdcqjy.property.base.BaseContract;
import com.sdcqjy.property.mode.LoginMode;
import com.sdcqjy.property.mode.MessageMode;
import com.sdcqjy.property.presenter.contract.MessageDetailsContract;
import com.sdcqjy.property.presenter.contract.a;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 磁磁帅 on 2018/5/13.
 * 功能：
 */

public class MessageDetailsPresenter extends BaseContract.Presenter<MessageDetailsContract.View> {
    public MessageDetailsPresenter(MessageDetailsContract.View baseView) {
        super(baseView);
    }

    public void getMode(long id) {
        Map<String, Object> map = new HashMap<>();
        //{"userID":"51","id":"0"}
        map.put("id", "" + id);
        LoginMode mode = LoginMode.getMode(AppLL.getAppLL());
        map.put("userID", mode.id);
        new HttpClient().setHttpType(HttpClient.HttpType.GET).setParam(map)
                .httpRequest(a.GetMsgDetails, new BaseRequestBack<BaseRet<MessageMode>>() {
                    public BaseRet<MessageMode> jsonToMode(String jsonStr) {
                        BaseRet<MessageMode> ret = new Gson().fromJson(jsonStr, new TypeToken<BaseRet<MessageMode>>() {
                        }.getType());
                        return ret;
                    }

                    public void onResponseSucc(BaseRet<MessageMode> ret) {
                        if (baseView != null) {
                            baseView.dismissDialog();
                            if (ret.isOk()) {
                                baseView.getModeRet(ret.data);
                            } else {
                                baseView.applyError(ret.msg);
                            }
                        }
                    }

                    public void onResponseFail(String retStr) {
                        if (baseView != null) {
                            baseView.dismissDialog();
                            baseView.applyError(retStr);
                        }
                    }
                });
        if (baseView != null) baseView.openLoadDialog();
    }
}
